<?php
class ImpSoft_View_Helper_CategoryTree {

	/**
	 * Accepts an array of items such as:
	 * array(
	 * 	{'name': 'Food', 'children': [
	 * 		{'name': 'Food', 'children': [
	 * 			{ // .. etc. },
	 * 			{ // .. etc. }
	 * 		]},
	 * 		{'name': 'Food', 'children': [
	 * 			{ // .. etc. },
	 * 			{ // .. etc. }
	 * 		]},
	 * 	]},
	 * 	// .. etc.
	 * )
	 */
	public function categoryTree($tree) {
	
		foreach ($tree as $branch) {
			echo "<li><a href=\"" . $this->view->routeUrl('product_category', array("slug" => $branch['slug'])) . "\">" . $branch['name'] . "</a>\n\t";
			// does this category have children?
			if (array_key_exists('children', $branch) && !empty($branch['children'])) {
				echo "<ul>\n";
				$this->categoryTree($branch['children']);
				echo "</ul>\n";
			}
			echo "</li>\n";
		}
	
	}
	
	public function setView(ImpSoft_View $view) {
	
		$this->view = $view;
	
	}

}